package com.xz.xzutils.test;

import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.execution.ui.layout.impl.JBRunnerTabs;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.tabs.TabInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * <p>
 *
 * </p>
 *
 * @author DONG.WANG17@HAND-CHINA.COM
 * @apiNote
 * @since 2025-01-13 16:18
 */
public class LogTab extends JBRunnerTabs {
    private final Project project;
    public LogTab(@Nullable Project project, @NotNull Disposable parent) {
        super(project, parent);
        this.project = project;
        // 初始化自定义控制台标签页
        initCustomTab();
    }

    private void initCustomTab() {
        // 创建 TabInfo 对象并添加自定义标签页
        TabInfo tabInfo = new TabInfo(createCustomComponent());
        tabInfo.setText("Custom Tab");
        addTab(tabInfo, getTabCount()); // 使用 getTabCount() 获取插入位置
    }

    private JComponent createCustomComponent() {
        // 创建一个 ConsoleView 实例
        ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(this.project).getConsole();
        consoleView.print("Hello, Console!\n", ConsoleViewContentType.NORMAL_OUTPUT);
        return consoleView.getComponent();
    }
}
